package multithread;

/**
 * @Author: zhangrongqing
 * @Date: 2019/12/18 10:38
 */
public class MultiThreadDemo {
    public static void main(String[] args) {
        ThreadLocalDemo threadLocalDemo = new ThreadLocalDemo();
        ThreadLocalDemo.setThreadLocal(threadLocalDemo);
        for (int i = 0; i < 10; i++) {
            threadLocalDemo.put("key" + i, "value" + i);
        }

        System.out.println(threadLocalDemo.get("key2"));

        System.out.println(ThreadLocalDemo.getThreadLocal());
        for (int i = 0; i < 10; i++) {
            new Thread(new Runnable() {
                @Override
                public void run() {
//                    ThreadLocalDemo.setThreadLocal(threadLocalDemo);
//                    for (int i = 0; i < 10; i++) {
//                        threadLocalDemo.put("key" + i, "value" + i);
//                    }
                    System.out.println(ThreadLocalDemo.getThreadLocal());
                }
            }).start();
        }
    }
}
